<!--
 * @FilePath: 删除节点.html
 * @Author: 苏苏少年
 * @Date: 2022-12-06 17:47:06
-->
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <!-- 
        删除节点
            removeChild() 从元素中移除子节点.
            
     -->
     <span id="programmer">程序员</span>
     <a href="javascript:void(0)" onclick="delNode();">删除</a>

</body>
<script>
    function delNode(){
        // 得到被删除的对象
        var span = document.getElementById("programmer");
        // 得到被删除的对象的父元素
        var parent = span.parentElement;
        // 删除元素
        parent.removeChild(span);

    }
</script>

</html>